Skip to content

feat: 支持自定义组件props类型提示支持#108

Open
Triumph-light wants to merge 3 commits into
mpx-ecology:mainfrom
Triumph-light:feat-reference-type-props
Open

feat: 支持自定义组件props类型提示支持#108
Triumph-light wants to merge 3 commits into
mpx-ecology:mainfrom
Triumph-light:feat-reference-type-props

Conversation

@Triumph-light

@Triumph-light Triumph-light commented May 12, 2026

Copy link
Copy Markdown
Collaborator

closes #86

Summary by CodeRabbit

  • Improvements

    • Enhanced runtime prop type handling and richer editor type generation for components.
    • Better IDE auto-completion, type inference, and navigation for components declared via templates and JSON metadata.
    • More accurate resolution of self-references, props, and slots in templates.
  • New Features

    • Added example components demonstrating different prop declaration styles.
  • Chores

    • Updated VS Code debug and workspace theme settings.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@wangshunnn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 32 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c6d4376d-837a-40a9-a1ae-6c42e14e67f8

📥 Commits

Reviewing files that changed from the base of the PR and between f655735 and a99a6df.

📒 Files selected for processing (2)
  • packages/language-core/src/codegen/script/jsonUsingComponents.ts
  • packages/language-core/src/codegen/template/element.ts
📝 Walkthrough

Walkthrough

Adds runtime prop-type utilities and richer component self typings; emits runtime JSON-declared component objects with stable import identifiers; integrates JSON components into script/template codegen and plugin plumbing; and adds example MPX components plus minor VSCode config updates.

Changes

Runtime Prop Types and JSON usingComponents Support

Layer / File(s) Summary
Global runtime prop type utilities
packages/language-core/src/codegen/globalTypes/defineComponentTypes.ts, packages/language-core/src/codegen/globalTypes/index.ts
New runtimePropTypes() codegen emits __VLS_ResolveProp/__VLS_GetPropsType utilities and is included in generated global types.
Enhanced component self typing
packages/language-core/src/codegen/script/componentSelf.ts
Generates expanded __VLS_self types (__VLS_SelfBase, __VLS_SelfComponent) with constructor signatures, $props, and slots.
JSON usingComponents runtime and naming
packages/language-core/src/codegen/script/jsonUsingComponents.ts
Emit runtime __MPX_jsonComponents object, build values as typeof unions of stable per-component import identifiers, and add getUsingComponentImportName() helper.
Script codegen reorganization
packages/language-core/src/codegen/script/index.ts
Emit JSON import/completion imports earlier (after script-setup imports); add scriptSetupImportComponentNames to ScriptCodegenOptions.
Template components and element resolution
packages/language-core/src/codegen/script/template.ts, packages/language-core/src/codegen/template/element.ts, packages/language-core/src/codegen/template/elementProps.ts, packages/language-core/src/codegen/template/templateChild.ts
Include typeof __MPX_jsonComponents in local components; resolve components via script-setup imports or stable JSON import names; adjust element routing and prop-check flags; emit navigation/type arrays for resolved imports.
Plugin integration
packages/language-core/src/plugins/mpx-tsx.ts
Compute selfComponentName from file basename and pass scriptSetupImportComponentNames into codegen.
Example components and IDE configs
inspect-extension/components/reference-type-props/component-js-setup.mpx, inspect-extension/components/reference-type-props/component-options.mpx, inspect-extension/components/reference-type-props/index.mpx, inspect-extension/components/script-json/components/list.mpx, .vscode/launch.json, inspect-extension/.vscode/settings.json
Adds example MPX components exercising typed props and options-style properties, updates parent templates with prop bindings and expected TS error comments, and tweaks VSCode launch/settings entries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • wangshunnn

Poem

🐰 Props aligned and names made neat,
Codegen hums with types complete,
JSON children find their place,
Self and slots now show their face,
A rabbit cheers for code so sweet!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive Most changes are scoped to component prop type hints, though updates to VS Code settings and debug configuration (.vscode files) appear tangential to the core objective. Clarify whether the .vscode configuration changes are necessary for the feature or if they should be separated into a different PR.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: 支持自定义组件props类型提示支持' accurately describes the main objective of adding type hint support for custom component props, which aligns with the changeset.
Linked Issues check ✅ Passed The PR implements type hint support for custom component props across multiple files, including new component definitions and TypeScript codegen helpers for prop type resolution.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/language-core/src/codegen/script/index.ts (1)

35-35: ⚡ Quick win

Add JSDoc for the new required field.

The scriptSetupImportComponentNames field is added without documentation. Consider adding a JSDoc comment explaining what component names are included (e.g., "Set of component names imported via default import from .mpx files in script setup").

📝 Proposed documentation
   scriptSetupRanges: ScriptSetupRanges | undefined
+  /**
+   * Set of component names imported via default import from .mpx files in <script setup>.
+   * Used for resolving component types in template code generation.
+   */
   scriptSetupImportComponentNames: Set<string>
   templateCodegen: (TemplateCodegenContext & { codes: Code[] }) | undefined
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/language-core/src/codegen/script/index.ts` at line 35, Add a JSDoc
comment above the scriptSetupImportComponentNames field describing its purpose
and contents: state that it is a Set<string> containing component names that are
imported via default import from .mpx files inside a script setup block (i.e.,
components brought into scope by `import X from "Y.mpx"` in script setup), note
that it is required and used to track which components should be treated as
locally registered in generated code, and include a short example usage to
clarify semantics.
packages/language-core/src/codegen/script/jsonUsingComponents.ts (1)

112-122: ⚡ Quick win

Consider adding index suffix for consistency.

The function returns just ${baseName} without any index suffix (line 121). When multiple paths resolve to the same component name, they'll have different indices, but the first one (index 0) won't have a distinguishing suffix. Consider returning ${baseName}_${index} or ${baseName}${index === 0 ? '' : _${index}} for consistency and to avoid potential name collisions if the same component name appears multiple times.

🔧 Proposed refinement for consistency
 export function getUsingComponentImportName(
   componentName: string,
   index: number,
 ) {
   const camelizedName = capitalize(camelize(componentName))
   const baseName =
     camelizedName && identifierRegex.test(camelizedName)
       ? camelizedName
       : `component_${index}`
-  return `${baseName}`
+  return index > 0 && camelizedName && identifierRegex.test(camelizedName)
+    ? `${baseName}_${index}`
+    : baseName
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/language-core/src/codegen/script/jsonUsingComponents.ts` around
lines 112 - 122, getUsingComponentImportName currently returns baseName without
an index suffix which can collide when the same componentName appears multiple
times; update the function (referencing getUsingComponentImportName,
camelizedName, identifierRegex, baseName) to append a deterministic index suffix
such as `${baseName}_${index}` (or `${baseName}${index === 0 ? '' :
`_${index}`}` if you want to keep the original for index 0) so each generated
import name is unique and consistent across duplicates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@inspect-extension/components/reference-type-props/component-options.mpx`:
- Around line 17-21: The JSON script block uses the incorrect symbol
"module.export"; update it to the standard Node.js export symbol
"module.exports" in the JSON script (the object assigned to module.exports) so
the export matches the rest of the codebase and other JSON blocks—locate the
script named "json" in component-options.mpx and replace module.export with
module.exports.

In `@inspect-extension/components/reference-type-props/index.mpx`:
- Line 3: This line intentionally uses a numeric literal for the msg prop of the
component-js-setup component to trigger type-checking; add an inline comment
next to the component invocation (component-js-setup msg="{{ 123 }}") stating
that this is test code in reference-type-props and that the number is an
intentional type mismatch for verification of the string-typed msg prop defined
in component-js-setup.mpx.
- Line 2: The parentText prop on the component-options component is receiving a
number ({{ 123 }}) while component-options.mpx defines parentText as type
String; either change the value to a string literal to match the declared type
(e.g., provide a string expression) or add an inline comment near the component
usage (or above the file) stating that the numeric value is intentionally used
to test type-checking; reference the component-options component and its
parentText prop declared in component-options.mpx when making the change so the
mismatch is resolved or explicitly documented.

---

Nitpick comments:
In `@packages/language-core/src/codegen/script/index.ts`:
- Line 35: Add a JSDoc comment above the scriptSetupImportComponentNames field
describing its purpose and contents: state that it is a Set<string> containing
component names that are imported via default import from .mpx files inside a
script setup block (i.e., components brought into scope by `import X from
"Y.mpx"` in script setup), note that it is required and used to track which
components should be treated as locally registered in generated code, and
include a short example usage to clarify semantics.

In `@packages/language-core/src/codegen/script/jsonUsingComponents.ts`:
- Around line 112-122: getUsingComponentImportName currently returns baseName
without an index suffix which can collide when the same componentName appears
multiple times; update the function (referencing getUsingComponentImportName,
camelizedName, identifierRegex, baseName) to append a deterministic index suffix
such as `${baseName}_${index}` (or `${baseName}${index === 0 ? '' :
`_${index}`}` if you want to keep the original for index 0) so each generated
import name is unique and consistent across duplicates.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 121ec58c-f129-469c-bdde-f34c59d885f7

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba7a6a and d35a9dc.

📒 Files selected for processing (14)
  • inspect-extension/components/reference-type-props/component-js-setup.mpx
  • inspect-extension/components/reference-type-props/component-options.mpx
  • inspect-extension/components/reference-type-props/index.mpx
  • inspect-extension/components/script-json/components/list.mpx
  • packages/language-core/src/codegen/globalTypes/defineComponentTypes.ts
  • packages/language-core/src/codegen/globalTypes/index.ts
  • packages/language-core/src/codegen/script/componentSelf.ts
  • packages/language-core/src/codegen/script/index.ts
  • packages/language-core/src/codegen/script/jsonUsingComponents.ts
  • packages/language-core/src/codegen/script/template.ts
  • packages/language-core/src/codegen/template/element.ts
  • packages/language-core/src/codegen/template/elementProps.ts
  • packages/language-core/src/codegen/template/templateChild.ts
  • packages/language-core/src/plugins/mpx-tsx.ts
💤 Files with no reviewable changes (1)
  • packages/language-core/src/codegen/template/templateChild.ts

Comment thread inspect-extension/components/reference-type-props/index.mpx
@@ -0,0 +1,21 @@
<template>
<component-options parentText="{{ 123 }}"></component-options>
<component-js-setup msg="{{ 123 }}"></component-js-setup>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

find . -type f -name "*.mpx" | grep -E "(component-js-setup|reference-type-props)" | head -20

Repository: mpx-ecology/language-tools

Length of output: 281


🏁 Script executed:

cat -n ./inspect-extension/components/reference-type-props/index.mpx

Repository: mpx-ecology/language-tools

Length of output: 668


🏁 Script executed:

cat -n ./inspect-extension/components/reference-type-props/component-js-setup.mpx

Repository: mpx-ecology/language-tools

Length of output: 220


🏁 Script executed:

ls -la ./inspect-extension/components/reference-type-props/

Repository: mpx-ecology/language-tools

Length of output: 384


Add a comment explaining this is test code for type-checking verification.

The msg prop is defined as string in component-js-setup.mpx, but receives {{ 123 }} (a number). Given this is in the reference-type-props test directory, this type mismatch appears intentional. Add a comment to clarify:

-  <component-js-setup msg="{{ 123 }}"></component-js-setup>
+  <!-- Test: intentional type error - number passed to string prop -->
+  <component-js-setup msg="{{ 123 }}"></component-js-setup>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<component-js-setup msg="{{ 123 }}"></component-js-setup>
<!-- Test: intentional type error - number passed to string prop -->
<component-js-setup msg="{{ 123 }}"></component-js-setup>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@inspect-extension/components/reference-type-props/index.mpx` at line 3, This
line intentionally uses a numeric literal for the msg prop of the
component-js-setup component to trigger type-checking; add an inline comment
next to the component invocation (component-js-setup msg="{{ 123 }}") stating
that this is test code in reference-type-props and that the number is an
intentional type mismatch for verification of the string-typed msg prop defined
in component-js-setup.mpx.

@Triumph-light Triumph-light requested a review from wangshunnn May 12, 2026 11:18
@wangshunnn wangshunnn changed the title feat: 支持自定义组件props类型提示支持, close: https://github.com/mpx-ecology/langu… feat: 支持自定义组件props类型提示支持 May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

支持自定义组件的属性提示

2 participants